PHP mysql_real_escape_string() returning `NULL`

Posted by DavidYell on Stack Overflow See other posts from Stack Overflow or by DavidYell
Published on 2010-05-18T10:51:48Z Indexed on 2010/05/18 11:20 UTC
Read the original article Hit count: 200

Filed under:
|

I'm using PHP Version 5.1.6 and trying to escape a query string from my $_GET array. However my script is returning a NULL after it's escaped.

It seems that mysql_escape_string() works fine, but it's deprecated, so I don't want to use it.

Having checked over the phpinfo() the MySQL lib is all loaded fine from what I can see. Has anyone experienced this kind of thing before?

$term = $_GET['q'];

var_dump($term); // string(7) "richard" 
echo "<br />";

$sterm = mysql_real_escape_string($term, $db);

var_dump($sterm); // NULL 

It's very strange to me, I can't imagine why this function wouldn't work.

© Stack Overflow or respective owner

Related posts about php

Related posts about php5